

#烤地瓜

#定义一个地瓜类
class SweetPotato:
    #默认的地瓜
    #定义初始化方法
    def __init__(self):
        self.cookedLevel = 0 #等级
        self.cookedString = "生的" #状态
        self.condiments = [] #调味品
    def __str__(self):
        msg = "地瓜等级为："+str(self.cookedLevel)
        msg += " 地瓜的生熟程度:"+self.cookedString
        if len(self.condiments) > 0:
            msg += " 作料为：("
            for temp in self.condiments:
                msg += temp + ","

            msg = msg[:-1]#切掉最后一个逗号
            msg = msg+")"
        else:
            msg += " 当前没有添加作料！" 

        return msg
    #烤地瓜方法
    def cook(self,times):
        self.cookedLevel += times
        if self.cookedLevel > 8:
            self.cookedString = "玛德，烤成灰了，吃个屁啊！"
        elif self.cookedLevel > 5:
            self.cookedString = "牛逼了我的哥，您的地瓜烤好了！"
        elif self.cookedLevel > 3:
            self.cookedString = "亚麻跌，在烤一会吧！还不熟啊！"
        else:
            self.cookedString = "八格牙路，生的吃毛线啊！"
    #添加作料
    def addCondiments(self,newCondiments):
        self.condiments.append(newCondiments)
digua = SweetPotato()
print(digua)
digua.cook(1)
print(digua)
digua.cook(2)
digua.addCondiments("辣椒油")
print(digua)
digua.cook(3)
digua.addCondiments("芥末")
print(digua)
digua.cook(4)
digua.addCondiments("芥末酱")
print(digua)
digua.cook(2)
digua.addCondiments("芥末酱")
print(digua)
digua.cook(1)
digua.addCondiments("芥末酱")
print(digua)